<template>
  <div>
    <ul>
      <li v-for="item in topicArr" :key="item.id">
        <img v-lazy="item.scene_pic_url" alt="" />
        <h2>{{ item.title }}</h2>
        <p>{{ item.subtitle }}</p>
        <span>￥{{ item.price_info }}元起</span>
      </li>
    </ul>
    <div class="btn">
<van-pagination v-model="page" :page-count="totalPages" mode="simple" @change='change' />
    </div>
    <tabbar></tabbar>
  </div>
</template>

<script>
import tabbar from "../components/Tabbar.vue";
import { topiclist } from "@/api/topic";
export default {
  name: "",
  data() {
    return {
      page: 1,
      size: 10,
      topicArr: [], //渲染的数据
      totalPages:''//总页数
    };
  },
  components: {
    tabbar,
  },
  methods:{
    //封装渲染函数
    gitlist(){
       topiclist({ page: this.page, size: this.size }).then((res) => {
      // console.log(res);
      this.topicArr = res.data.data;
      this.totalPages=res.data.totalPages
      document.documentElement.scrollTop = 0//返回首页
      // console.log(this.totalPages);
    })
    },
    //页码改变时触发
    change(){
      this.gitlist()
    }
  },
  mounted() {
   this.gitlist()
   
  },
};
</script>
<style scoped lang='less'>
ul {
  width: 100%;
  height: 100%;
  li {
    width: 100%;
    height: 350px;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
    img {
      width: 100%;
      height: 60%;
    }
    h2 {
      font-size: 20px;
      margin-top: 25px;
    }
    p {
      width: 100%;
      height: 25px;
      font-size: 16px;
      margin-top: 20px;
      line-height: 25px;
      text-align: center;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    span {
      margin-top: 25px;
      font-size: 16px;
      color: red;
    }
  }
}
.btn{
  padding-bottom: 60px;
  width: 100%;
  height: 100px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.van-button{
  width: 50%;
}
</style>